//
// Created by zhengjuping on 24-8-16.
//

#ifndef ENV_II_SENSORMANAGER_H
#define ENV_II_SENSORMANAGER_H

#include <list>
#include <cstdint>
#include <chrono>
#include <thread>

#include "BMP280.h"
#include "SHT30.h"
#include "ISensorObserver.h"


class SensorManager {
public:
    SensorManager();
    ~SensorManager();

    int32_t start( std::chrono::milliseconds interval );
    int32_t stop();

    void registerObserver(ISensorObserver *observer);
    void unregisterObserver(ISensorObserver *observer);

private:
    void notifyObservers(float temperature, float humidity, float pressure);

    std::list<ISensorObserver *> _observers;
    std::thread _sensorCaptureThread;
    bool _isRunning;

    std::unique_ptr<BMP280> _bmp280;
    std::unique_ptr<SHT30> _sht30;
};


#endif //ENV_II_SENSORMANAGER_H
